package net.interneteidee.converter;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import net.interneteidee.entity.Categoria;
import net.interneteidee.entity.Regione;

@ManagedBean
@SessionScoped
public class RegioneConverter extends GenericConverter {
	
	@Override
    public Object getAsObject(FacesContext facescontext, UIComponent uicomponent, String value) {
        if (value == null) return null;
       
       String [] ris = value.split("-");
       int idRegione = Integer.parseInt(ris[0]);
       
       Regione regione = clienteService.findRegioneById(idRegione);
       
       return clienteService.findRegioneById(idRegione);

       
    }

    @Override
    public String getAsString(FacesContext facescontext, UIComponent uicomponent, Object obj) {
        if (obj == null) return null;
        return ((Regione)obj).getIdRegione()+"-"+((Regione) obj).getNomeRegione();
	       
    }

}
